<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <!-- import CSS -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/element-ui/2.15.9/theme-chalk/index.css">
    <style>
        header a{
            text-decoration: none;
            color: #6c6c6c;
        }
        .el-table .el-table__cell{
            padding: 0;
        }
        .el-table .cell{
            white-space: nowrap;/*设置内容不换行*/
            text-overflow: ellipsis;
        }
        .p_img:hover{
            position: relative;
            top: 5px;
            box-shadow: 0 0 10px 5px #333;
        }
    </style>
</head>
<body>
<div id="app">
    <el-container>
        <el-header height="110px" style="padding: 0">
            <div style="width: 2200px;margin: 0 auto">
                <el-row :gutter="20">
                    <el-col :span="12"><div class="grid-content bg-purple"><a href="/"><img src="images/stumalllogo.png"></a></div></el-col>
                    <el-col :span="12" ><div class="grid-content bg-purple" >
                        <div class="line"></div>
                        <el-menu
                                :default-active="activeIndex2"
                                class="el-menu-demo"
                                mode="horizontal"
                                @select="handleSelect2"
                                text-color="#f"
                        >
                            <el-menu-item index="1"class="el-icon-star-on">收藏</el-menu-item>
                            <el-menu-item index="2"class="el-icon-s-order">订单</el-menu-item>
                            <el-menu-item index="3"class="el-icon-shopping-cart-full">购物车</el-menu-item>
                            <el-submenu index="4">
                                <template slot="title" class="el-icon-s-tools">管理</template>
                                <el-menu-item index="4-1"class="el-icon-s-operation">修改密码</el-menu-item>
                                <el-menu-item index="4-2"class="el-icon-user-solid">个人资料</el-menu-item>
                                <el-menu-item index="4-3"class="el-icon-picture">上传头像</el-menu-item>
                                <el-menu-item index="4-4"class="el-icon-s-home">收货管理</el-menu-item>
                            </el-submenu>
                            <el-menu-item index="5"class="el-icon-s-custom"     v-if="user==null">登录</el-menu-item>
                            <el-menu-item index="6"class="el-icon-edit-outline" v-if="user==null">注册</el-menu-item>
                            <el-menu-item index="7"class="el-icon-sunny" v-if="user!=null">欢迎回来</el-menu-item>
                            <el-menu-item index="8"class="el-icon-switch-button" v-if="user!=null">退出登录</el-menu-item>
                        </el-menu>
                    </div></el-col>
                </el-row>

            </div>
            <!--导航菜单开始-->
            <div style="background-color: #82c8ec;" >
                <el-menu style="width: 1200px;margin: 0 auto"
                         :default-active="activeIndex"
                         class="el-menu-demo"
                         mode="horizontal"

                         background-color="#82c8ec"
                         text-color="#fff"
                         active-text-color="#fff" >
                    <el-menu-item   v-for="a in activityArr" :index="a.id"><a :href="a.url">{{a.name}}</a></el-menu-item>
                    <div style="float: right;position: relative;top: 10px">
                        <el-input placeholder="请输入搜索内容" v-model="wd">
                            <el-button slot="append" icon="el-icon-search" @click="search()"></el-button>
                        </el-input>
                    </div>
                </el-menu>
            </div>
            <!--导航菜单结束-->

        </el-header>
        <el-main style="width: 1200px;margin: 0 auto">
            <el-row gutter="20" >
                <el-col style="margin: 10px 0" span="6" v-for="(p,index) in favProductArr" >
                    <el-card >
                        <a :href="'/detail.html?id='+p.id" style="text-decoration: none;color:#3f3f3f;">
                            <img class="p_img" :src="p.url" width="200px" height="200px" alt="">
                        </a>
                        <div>
                            <p style="font-size: 15px;height: 40px;margin-top: 0">
                                <a :href="'/detail.html?id='+p.id" style="text-decoration: none;color:#3f3f3f;">
                                    {{p.title}}
                                </a>
                            </p>
                            <p style="font-size: 12px;color: #666">
                                ￥{{p.price}} 浏览量{{p.viewCount}}
                                <span style="float: right">销量:{{p.saleCount}}件</span>
                            </p>

                           <el-button type="primary"  size="small"  icon="el-icon-edit" @click="favorites(p.id,index)">取消收藏</el-button>
                           <el-button type="primary"  size="small"  icon="el-icon-edit">加入购物车</el-button>
                        </div>
                    </el-card>
                </el-col>
            </el-row>
                       <!--  分页          -->
            <div style="text-align:center">
                <el-pagination
                        @current-change="handleCurrentChange"
                        :current-page.sync="currentPage1"
                        page-size="12"
                        pager-count="7"
                        background="true"
                        layout=" prev, pager, next"
                        :total="totalNum">
                </el-pagination>
            </div>

        </el-main>
        <el-footer>
            <div style="height: 95px;background-image: url('images/wave.png')">
            </div>
            <div style="background-color: #3f3f3f;padding:30px 0;text-align: center;color: #b1b1b1">
                页脚
            </div>
        </el-footer>
    </el-container>
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<!-- import Vue before Element -->
<script src="https://cdn.staticfile.org/vue/2.6.14/vue.min.js"></script>
<!-- import JavaScript -->
<script src="https://cdn.staticfile.org/element-ui/2.15.9/index.min.js"></script>
<script>
   let v = new Vue({
        el: '#app',
        data: function() {
            return {
                valNum:1,
                totalNum:5,
                currentPage1: 1,
                user:null,
                favProductArr:[{title:'1'}],
                activityArr:[{name:"a"}],
                activeIndex:"",
                activeIndex2: '',
                wd:"",
                productArr:[]
            }
        },
       methods: {
           favoritesList(){
               axios.get("/favorites").then(function (response){
                   v.favProductArr = response.data.data;
               })
               axios.get("/favorites/count").then(function (response){
                   v.count = response.data.data;
                   v.totalNum = response.data.data;
               })
           },
           handleCurrentChange(val) {
          axios.get("/favorites/select?index="+val).then(function (response) {
                   v.favProductArr=response.data.data;
           })
           },
           handleSelect(key,keyPath){
               console.log(key,keyPath);
               location.href="/result.html?id="+key;
           },
           search(){
               location.href="/result.html?wd="+v.wd;
           },
           handleSelect2(key, keyPath) {
               console.log(key, keyPath);
               if(key==1){
                   location.href="/favorites.html";
               }else if(key==2){
                   location.href="";
               }else if(key==3){
                   location.href="";
               }else if(key=='4-1'){
                   location.href="/login1.html";
               }else if(key=='4-2'){
                   location.href="";
               }else if(key=='4-3'){
                   location.href="";
               }else if(key=='4-4'){
                   location.href="";
               }else if(key==5){
                   location.href="/login.html";
               }else if(key==6){
                   location.href="/reg.html";
               }else if(key==7){

               }else if(key==8){
                   axios.get("/logout").then(function (response){
                       v.$message.success("退出成功");
                       location.href="/"
                   })
               }
           },
           favorites(id,index){
               axios.get("/favorites/delete?id="+id).then(function (response){
                   v.$message.success("取消收藏成功")
                   // v.favProductArr.splice(index,1);
               })
               this.favoritesList();
           }
       },
       mounted(){
           axios.get("/getUser").then(function (response){
               v.user = response.data;
           })
        // axios.get("category/select").then(function (response){
        //     v.categoryArr = response.data;
        // })
        // axios.get("/banner/select").then(function (response){
        //        v.bannerArr = response.data;
        // })
        // axios.get("/product/select/top").then(function (response){
        //        v.topArr = response.data;
        // })
        // axios.get("/product/select/index").then(function (response){
        //       v.productArr = response.data;
        // })
        // axios.get("/product/hotProduct/index").then(function (response){
        //        v.hotProductArr = response.data;
        // })
        // axios.get("/product/newProduct/index").then(function (response){
        //        v.newProductArr = response.data;
        // })
        axios.get("/activity").then(function (response){
               v.activityArr = response.data;
        })
           this.favoritesList();

       }

   })
</script>
</html>
